
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="mall/header::head-fragment('NewBee商城-搜索','search')">
    <link rel="stylesheet" th:href="@{/mall/css/swiper-bundle.min.css}">
    <link rel="stylesheet" th:href="@{/mall/css/iconfont.css}">
    <link rel="stylesheet" th:href="@{/mall/css/common.css}">
    <link rel="stylesheet" th:href="@{/admin/plugins/sweetalert2/sweetalert2.min.css}"/>
</head>
<body>
<header th:replace="mall/header::header-fragment"></header>
<!-- nav -->
<nav th:replace="mall/header::nav-fragment"></nav>

<!--分类筛选-->
<div class="classify">
    <div class="category">
        <div class="category_bar">
            <th:block th:if="${secondCategories!=null}">
                <div class="fm c">
                    <a href="##" class="qqq" th:text="${parentCategory.name}">newbee-mall</a>
                    <div>
                        <th:block th:each="secondCategory : ${secondCategories}">
                            <a th:href="@{${'/shopping/item/search?id='+secondCategory.id}}"
                               th:text="${secondCategory.name}">newbee-mall</a>
                        </th:block>
                    </div>
                </div>
                <i><img th:src="@{/mall/image/123123.png}" alt=""></i>
                <div class="findword">"
                    <th:block th:text="${itemCategory.name}"></th:block>
                    "
                </div>
            </th:block>
        </div>
    </div>
</div>
<!--排序-->
<div class="sort">
    <div class="list">
        <a th:href="@{/shopping/item/search(id=${categoryId ?: ''}, orderBy='default')}">
            <div th:class="${orderBy==null || orderBy=='default'?'active':''}">推荐</div>
        </a>
        <a th:href="@{/shopping/item/search(id=${categoryId ?: ''}, orderBy='new')}">
            <div th:class="${orderBy=='new'?'active':''}">新品</div>
        </a>
        <a th:href="@{/shopping/item/search(id=${categoryId ?: ''}, orderBy='price')}">
            <div th:class="${orderBy=='price'?'active':''}">全部</div>
        </a>
    </div>
</div>
<div class="goods_item center">
    <div class="main center">
        <th:block th:if="${#lists.isEmpty(showItems)}">
            <img style="margin-top: 16px;padding: 16px 20px;" th:src="@{/mall/image/null-content.png}">
        </th:block>
        <th:block th:unless="${#lists.isEmpty(showItems)}">
            <th:block th:each="showItem : ${showItems}">
                <div class="item_card_frame">
                    <div class="item_card">
                        <a th:href="@{'/shopping/item/detail/'+${showItem.id}}" th:attr="data-name=${showItem.name}">
                            <img th:src="@{${showItem.image}}" th:alt="${showItem.name}">
                        </a>
                    </div>
                    <div class="item_brand">
                        <a th:href="@{'/shopping/item/detail/'+${showItem.id}}" th:text="${showItem.name}">商品名称</a>
                    </div>

                    <div class="item_sub_intro" th:text="${showItem.description}">newbee.ltd</div>
                    <div class="item_price" th:text="${showItem.sellPrice+'0元'}">1299.00元</div>
                </div>
            </th:block>
        </th:block>
        <div class="clear"></div>
    </div>
<!--    <div class="pages">-->
<!--        <div class="page_wrap">-->
<!--            <th:block th:if="${pageResult != null}">-->
<!--            <span class="page_span1">-->
<!--                &lt;!&ndash; 上一页 &ndash;&gt;-->
<!--                <a th:href="@{${pageResult.current <= 1} ? '##' : '/item/search?id=' + ${categoryId} + '&orderBy=' + ${orderBy} + '&pageNo=' + ${pageResult.current - 1} + '&pageSize=' + ${pageResult.size}}"-->
<!--                   th:text="'< 上一页'">上一页</a>-->

<!--                &lt;!&ndash; 显示前两页 &ndash;&gt;-->
<!--                <th:block th:if="${pageResult.current - 2 >= 1}">-->
<!--                    <a th:href="@{'/item/search?id=' + ${categoryId} + '&orderBy=' + ${orderBy} + '&pageNo=' + ${pageResult.current - 2} + '&pageSize=' + ${pageResult.size}}"-->
<!--                       th:text="${pageResult.current - 2}">1</a>-->
<!--                </th:block>-->

<!--                &lt;!&ndash; 显示前一页 &ndash;&gt;-->
<!--                <th:block th:if="${pageResult.current - 1 >= 1}">-->
<!--                    <a th:href="@{'/item/search?id=' + ${categoryId} + '&orderBy=' + ${orderBy} + '&pageNo=' + ${pageResult.current - 1} + '&pageSize=' + ${pageResult.size}}"-->
<!--                       th:text="${pageResult.current - 1}">1</a>-->
<!--                </th:block>-->

<!--                &lt;!&ndash; 当前页 &ndash;&gt;-->
<!--                <span class="active" th:text="${pageResult.current}">1</span>-->

<!--                &lt;!&ndash; 显示下一页 &ndash;&gt;-->
<!--                <th:block th:if="${pageResult.current + 1 <= pageResult.pages}">-->
<!--                    <a th:href="@{'/item/search?id=' + ${categoryId} + '&orderBy=' + ${orderBy} + '&pageNo=' + ${pageResult.current + 1} + '&pageSize=' + ${pageResult.size}}"-->
<!--                       th:text="${pageResult.current + 1}">1</a>-->
<!--                </th:block>-->

<!--                &lt;!&ndash; 显示后两页 &ndash;&gt;-->
<!--                <th:block th:if="${pageResult.current + 2 <= pageResult.pages}">-->
<!--                    <a th:href="@{'/item/search?id=' + ${categoryId} + '&orderBy=' + ${orderBy} + '&pageNo=' + ${pageResult.current + 2} + '&pageSize=' + ${pageResult.size}}"-->
<!--                       th:text="${pageResult.current + 2}">1</a>-->
<!--                </th:block>-->

<!--                &lt;!&ndash; 下一页 &ndash;&gt;-->
<!--                <a th:href="@{${pageResult.current >= pageResult.pages} ? '##' : '/item/search?id=' + ${categoryId} + '&orderBy=' + ${orderBy} + '&pageNo=' + ${pageResult.current + 1} + '&pageSize=' + ${pageResult.size}}"-->
<!--                   th:text="'下一页 >'">下一页</a>-->
<!--            </span>-->
<!--            </th:block>-->
<!--        </div>-->
<!--    </div>-->
    <!-- 分页模块 -->
    <div class="pagination">
        <ul class="pagination_list">
            <!-- 上一页 -->
            <li class="page-item" th:classappend="${pageResult.current <= 1 ? 'disabled' : ''}">
                <a th:href="@{${pageResult.current <= 1} ? '##' : '/shopping/item/search?id=' + ${categoryId} + '&orderBy=' + ${orderBy} + '&pageNo=' + ${pageResult.current - 1} + '&pageSize=' + ${pageResult.size}}"
                   class="page-link" th:text="'&laquo;'">«</a>
            </li>

            <!-- 页码 -->
            <th:block th:each="page : ${#numbers.sequence(1, pageResult.pages)}">
                <li class="page-item" th:classappend="${page == pageResult.current ? 'active' : ''}">
                    <a th:href="@{'/shopping/item/search?id=' + ${categoryId} + '&orderBy=' + ${orderBy} + '&pageNo=' + ${page} + '&pageSize=' + ${pageResult.size}}"
                       class="page-link" th:text="${page}">1</a>
                </li>
            </th:block>

            <!-- 下一页 -->
            <li class="page-item" th:classappend="${pageResult.current >= pageResult.pages ? 'disabled' : ''}">
                <a th:href="@{${pageResult.current >= pageResult.pages} ? '##' : '/shopping/item/search?id=' + ${categoryId} + '&orderBy=' + ${orderBy} + '&pageNo=' + ${pageResult.current + 1} + '&pageSize=' + ${pageResult.size}}"
                   class="page-link" th:text="'&raquo;'">»</a>
            </li>
        </ul>
    </div>
</div>
<div th:replace="mall/footer::footer-fragment"></div>
<!-- jQuery -->
<script th:src="@{/admin/plugins/jquery/jquery.min.js}"></script>
<script th:src="@{/mall/js/search.js}" type="text/javascript"></script>
<script>
    $(document).ready(function() {
        $(".goods_item").on("click", "a", function(event) {
            var $link = $(this);
            var href = $link.attr("href");
            var id = $link.data("id");
            var name = $link.data("name");

            // 如果没有data-id，从href中提取数字ID
            if (!id && href) {
                var match = href.match(/(\d+)/);
                if (match) {
                    id = match[1];
                }
            }

            if (!name) {
                name = $link.find(".name").text() || $link.text() || "";
            }
            var userId = window.currentUserId || localStorage.getItem("currentUserId") || "anonymous";
            var eventData = {
                userId: userId,
                productId: id || "unknown",
                productName: name || "unknown",
                timestamp: new Date().toISOString()
            };

            // 发送点击行为
            $.ajax({
                url: '/api/track/click',
                method: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(eventData),
                success: function() {
                    console.log("点击事件已发送：", eventData);
                },
                error: function(err) {
                    console.error("点击事件发送失败：", err);
                }
            });
        });
    });

</script>
</body>
</html>